#pragma once 

#include <iostream>
#include <string>

std::string opers = "+-*/%";

enum 
{
    DivZero = 1,
    ModZero,
    NotFound
};
 
class Task
{
public:
    Task(int num1, int num2, char oper)
        : _num1(num1)
        , _num2(num2)
        , _oper(oper)
        , _result(0)
        , _exit_code(0)
    {}

    // 实行任务
    void run()
    {
        switch(_oper)
        {
        case '+':
            _result = _num1 + _num2;
            break;

        case '-':
            _result = _num1 - _num2;
            break;

        case '*':
            _result = _num1 * _num2;
            break;

        case '/':
            if (_num2 == 0)  _exit_code = DivZero;
            else _result = _num1 / _num2;
            break;

        case '%':
            if (_num2 == 0) _exit_code = ModZero;
            else _result = _num1 % _num2;
            break;
        }
    }

    void operator()() {  run(); }

    std::string get_result()
    {
        std::string gt = std::to_string(_num1);
        gt += _oper;
        gt += std::to_string(_num2);
        gt += "=";
        gt += std::to_string(_result);
        gt += "[exit code: ";
        gt += std::to_string(_exit_code);
        gt += "]";
    }

    // 说明任务
    std::string get_task()
    {
        std::string gt = std::to_string(_num1);
        gt += _oper;
        gt += std::to_string(_num2);
        gt += "=?";
        return gt;
    }

    ~Task()
    {}

private:
    int _num1;
    int _num2;
    char _oper;

    int _result;
    int _exit_code;
};
